import { mutableHandlers,readonlyHandlers,shallowReadonlyHandlers } from "./baseHandlers"

// 定义枚举数据
export const enum ReactiveFlags {
    IS_REACTIVE = "__v_isReactive",
    IS_READONLY = "__v_isReadonly",
}

export function reactive(raw) {
    return createActiveObject(raw,mutableHandlers)
}

export function readonly(raw) {
    return createActiveObject(raw,readonlyHandlers)
}

export function shallowReadonly(raw) {
    return createActiveObject(raw,shallowReadonlyHandlers)
}

export function isReactive(value) {
    // 双非：就是如果是undefined会转换为false
    return !!value[ReactiveFlags.IS_REACTIVE]
}

export function isReadonly(value) {
    // 双非：就是如果是undefined会转换为false
    return !!value[ReactiveFlags.IS_READONLY]
}

export function isProxy(value) {
    return isReactive(value) || isReadonly(value)
}

function createActiveObject(raw,baseHandlers) {
    return new Proxy(raw,baseHandlers)
}